package com.wecloud.core.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.wecloud.core.constant.ErrorMsg;


public class WeException  extends RuntimeException{
	/**
	 * 自定义异常类
	 */
	Logger logger = LoggerFactory.getLogger(WeException.class);
	
	private static final long serialVersionUID = 1L;
	private String msg;
	private Throwable e;
	private String code;
	
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public Throwable getE() {
		return e;
	}
	public void setE(Throwable e) {
		this.e = e;
	}
	public WeException(String msg, Throwable e) {
		super(msg,e);
		this.msg = msg;
		this.e = e;
		logger.error("there is an Exception it my caused by:"+msg, e);
	}
	public WeException(String msg,ErrorMsg code) {
		super(msg);
		this.msg = code.getDesc();
		this.code = code.getRtnCode();
		logger.error("there is an Exception it my caused by:"+msg);
	}
	public WeException(ErrorMsg code) {
		super(code.getDesc());
		this.msg = code.getDesc();
		this.code = code.getRtnCode();
		logger.error("there is an Exception it my caused by:"+msg);
	}
	public WeException(Throwable e) {
		super(e);
		this.e = e;
		this.msg = e.getMessage();
		logger.error("there is an Exception it my caused by:",e);
	}
	public String toString(){
		return this.getMessage() + "|" + this.getE();
	}
	 public String getMessage() {
		if(this.msg.length() > 300){
			 this.msg = this.msg.substring(0, 300);
		 }
	     return this.msg;
	 }
}
